package com.visizen.wisdomclass.server.client;

import com.visizen.wisdomclass.server.model.WcFamily;
import com.visizen.wisdomclass.server.model.WcFamilyExample;
import com.visizen.wisdomclass.server.model.WcUser;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface WcFamilyMapper {
    //查询给定学生ID的所有家长信息
    @Select("SELECT * FROM wc_family WHERE student_id=#{studentId}")
    @Results({
            @Result(property = "user", column = "family_user_id", one = @One(select = "getUserByUserId"))
    })
    List<WcFamily> getFamilyListByStudentId(@Param("studentId") long studentId);

    //查询给定家长ID的所有孩子信息
    @Select("SELECT * FROM wc_family WHERE family_user_id=#{familyId}")
    @Results({
            @Result(property = "user", column = "student_id", one = @One(select = "getUserByUserId"))
    })
    List<WcFamily> getChildListByFamilyId(@Param("familyId") long familyId);

    //通过用户ID查询用户的信息
    @Select("SELECT * FROM wc_user WHERE user_id=#{userId}")
    WcUser getUserByUserId(@Param("userId") long userId);

    /**
     * This method was generated by MyBatis Generator. This method corresponds to the database table wc_family
     *
     * @mbggenerated
     */
    @SelectProvider(type = WcFamilySqlProvider.class, method = "countByExample")
    int countByExample(WcFamilyExample example);

    /**
     * This method was generated by MyBatis Generator. This method corresponds to the database table wc_family
     *
     * @mbggenerated
     */
    @DeleteProvider(type = WcFamilySqlProvider.class, method = "deleteByExample")
    int deleteByExample(WcFamilyExample example);

    /**
     * This method was generated by MyBatis Generator. This method corresponds to the database table wc_family
     *
     * @mbggenerated
     */
    @Delete({"delete from wc_family", "where id = #{id,jdbcType=BIGINT}"})
    int deleteByPrimaryKey(Long id);

    /**
     * This method was generated by MyBatis Generator. This method corresponds to the database table wc_family
     *
     * @mbggenerated
     */
    @Insert({"insert into wc_family (id, student_id, ",
            "family_user_id, ismain, ", "relation)",
            "values (#{id,jdbcType=BIGINT}, #{student_id,jdbcType=BIGINT}, ",
            "#{family_user_id,jdbcType=BIGINT}, #{ismain,jdbcType=INTEGER}, ",
            "#{relation,jdbcType=VARCHAR})"})
    int insert(WcFamily record);

    /**
     * This method was generated by MyBatis Generator. This method corresponds to the database table wc_family
     *
     * @mbggenerated
     */
    @InsertProvider(type = WcFamilySqlProvider.class, method = "insertSelective")
    int insertSelective(WcFamily record);

    /**
     * This method was generated by MyBatis Generator. This method corresponds to the database table wc_family
     *
     * @mbggenerated
     */
    @SelectProvider(type = WcFamilySqlProvider.class, method = "selectByExample")
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "student_id", property = "student_id", jdbcType = JdbcType.BIGINT),
            @Result(column = "family_user_id", property = "family_user_id", jdbcType = JdbcType.BIGINT),
            @Result(column = "ismain", property = "ismain", jdbcType = JdbcType.INTEGER),
            @Result(column = "relation", property = "relation", jdbcType = JdbcType.VARCHAR)})
    List<WcFamily> selectByExample(WcFamilyExample example);

    /**
     * This method was generated by MyBatis Generator. This method corresponds to the database table wc_family
     *
     * @mbggenerated
     */
    @Select({"select", "id, student_id, family_user_id, ismain, relation",
            "from wc_family", "where id = #{id,jdbcType=BIGINT}"})
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "student_id", property = "student_id", jdbcType = JdbcType.BIGINT),
            @Result(column = "family_user_id", property = "family_user_id", jdbcType = JdbcType.BIGINT),
            @Result(column = "ismain", property = "ismain", jdbcType = JdbcType.INTEGER),
            @Result(column = "relation", property = "relation", jdbcType = JdbcType.VARCHAR)})
    WcFamily selectByPrimaryKey(Long id);

    /**
     * This method was generated by MyBatis Generator. This method corresponds to the database table wc_family
     *
     * @mbggenerated
     */
    @UpdateProvider(type = WcFamilySqlProvider.class, method = "updateByExampleSelective")
    int updateByExampleSelective(@Param("record") WcFamily record,
                                 @Param("example") WcFamilyExample example);

    /**
     * This method was generated by MyBatis Generator. This method corresponds to the database table wc_family
     *
     * @mbggenerated
     */
    @UpdateProvider(type = WcFamilySqlProvider.class, method = "updateByExample")
    int updateByExample(@Param("record") WcFamily record,
                        @Param("example") WcFamilyExample example);

    /**
     * This method was generated by MyBatis Generator. This method corresponds to the database table wc_family
     *
     * @mbggenerated
     */
    @UpdateProvider(type = WcFamilySqlProvider.class, method = "updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(WcFamily record);

    /**
     * This method was generated by MyBatis Generator. This method corresponds to the database table wc_family
     *
     * @mbggenerated
     */
    @Update({"update wc_family",
            "set student_id = #{student_id,jdbcType=BIGINT},",
            "family_user_id = #{family_user_id,jdbcType=BIGINT},",
            "ismain = #{ismain,jdbcType=INTEGER},",
            "relation = #{relation,jdbcType=VARCHAR}",
            "where id = #{id,jdbcType=BIGINT}"})
    int updateByPrimaryKey(WcFamily record);
}